﻿@using Moonglade.Core
@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment WebHostEnvironment

<!DOCTYPE html>
<html>
<head>
    <title>
        @(ViewBag?.TitlePrefix)@(null == ViewBag?.TitlePrefix ? string.Empty : " - ")@BlogConfig.GeneralSettings.SiteTitle
        <environment exclude="Production">
            (@WebHostEnvironment.EnvironmentName)
        </environment>
    </title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
    @if (IsSectionDefined("keywords"))
    {
        @await RenderSectionAsync("keywords", false)
    }
    else
    {
        <meta name="keywords" content="@Html.Raw(BlogConfig.GeneralSettings.MetaKeyword)" />
    }

    @await RenderSectionAsync("meta", false)
    @if (BlogConfig.AdvancedSettings.EnableOpenGraph)
    {
        if (IsSectionDefined("opengraph"))
        {
            @await RenderSectionAsync("opengraph", false)
        }
        else
        {
            <meta property="og:site_name" content="@BlogConfig.GeneralSettings.SiteTitle">
            <meta property="og:title" content="@(ViewBag?.TitlePrefix)@(null == ViewBag?.TitlePrefix ? string.Empty : " - ")@BlogConfig.GeneralSettings.SiteTitle">
            <meta property="og:type" content="website" />
            <meta property="og:description" content="@BlogConfig.GeneralSettings.MetaDescription" />
        }
    }

    @if (IsSectionDefined("metadescription"))
    {
        @await RenderSectionAsync("metadescription", false)
    }
    else
    {
        <meta name="description" content="@BlogConfig.GeneralSettings.MetaDescription" />
    }

    @if (!string.IsNullOrWhiteSpace(BlogConfig.AdvancedSettings.DNSPrefetchEndpoint))
    {
        <link rel="dns-prefetch" href="@BlogConfig.AdvancedSettings.DNSPrefetchEndpoint" />
    }

    @if (!string.IsNullOrWhiteSpace(BlogConfig.GeneralSettings.CanonicalPrefix))
    {
        <link rel="canonical" href="@(Utils.ResolveCanonicalUrl(BlogConfig.GeneralSettings.CanonicalPrefix, Context.Request.Path))" />
    }

    <link rel="start" title="@BlogConfig.GeneralSettings.SiteTitle" href="~/" />
    <link rel="alternate" type="application/rss+xml" title="@BlogConfig.FeedSettings.RssTitle" href="~/rss" />
    <link type="application/opensearchdescription+xml" rel="search" title="@BlogConfig.GeneralSettings.SiteTitle" href="~/opensearch" />
    <partial name="_Favicons" />
    <link href="~/css/mooglade-css-bundle.min.css" rel="stylesheet" asp-append-version="true" />
    <script src="~/js/dist/app-js-bundle.min.js" asp-append-version="true"></script>
    @await RenderSectionAsync("head", false)
    <environment include="Production">
        @Html.Raw(JavaScriptSnippet.FullScript)
    </environment>
    <link href="~/css/theme/@BlogConfig.GeneralSettings.ThemeFileName" rel="stylesheet" asp-append-version="true" />
</head>
<body class="@ViewBag.BodyClass">
    <header class="ediblog-header">
        <nav id="moonglade-nav" class="navbar fixed-top navbar-expand-lg navbar-dark bg-accent1">
            <div class="container">
                <div class="animbrand">
                    <a class="moonglade-logo font-sairas navbar-brand animate" href="/">
                        @BlogConfig.GeneralSettings.LogoText
                    </a>
                </div>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#moonglade-navbar-content" aria-controls="moonglade-navbar-content" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="moonglade-navbar-content">
                    <ul class="navbar-nav mr-auto">
                        <!-- System Nav Menu -->
                        @if (Settings.Value.SystemNavMenus["Categories"])
                        {
                            <li id="navbar-dropdown-post" class="nav-item dropdown">
                                <a href="#" class="nav-link dropdown-toggle" role="button" data-toggle="dropdown">
                                    <span class="icon-book"></span>
                                    <strong>@Localizer["Categories"]</strong>
                                </a>
                                @await Component.InvokeAsync("CategoryList", new { isMenu = true })
                            </li>
                        }

                        @if (Settings.Value.SystemNavMenus["Tags"])
                        {
                            <li class="nav-item">
                                <a asp-controller="Tags" asp-action="Index" class="nav-link">
                                    <span class="icon-price-tag"></span>
                                    <strong>@Localizer["Tags"]</strong>
                                </a>
                            </li>
                        }

                        @if (Settings.Value.SystemNavMenus["Archive"])
                        {
                            <li class="nav-item">
                                <a asp-controller="Archive" asp-action="Index" class="nav-link">
                                    <span class="icon-folder"></span>
                                    <strong>@Localizer["Archive"]</strong>
                                </a>
                            </li>
                        }

                        @await Component.InvokeAsync("Menu")
                    </ul>
                    <form class="form-inline search-form my-2 my-lg-0" asp-controller="Search" asp-action="Index">
                        <input id="term"
                               class="form-control bg-transparent mr-sm-2"
                               type="search"
                               value=""
                               title="@Localizer["Search"]"
                               aria-label="Search"
                               placeholder="@Localizer["Search"]"
                               name="term"
                               maxlength="30">
                        <button class="btn btn-outline-light btn-search my-2 my-sm-0 d-none d-md-block" type="submit"><span class="icon-search"></span></button>
                        <button class="btn btn-block btn-success d-block d-sm-none mt-1" type="submit"><span class="icon-search"></span> @Localizer["Search"]</button>
                    </form>
                </div>
            </div>
        </nav>
    </header>

    @if (BlogConfig.ContentSettings.ShowCalloutSection)
    {
        <section class="call-out">
            @Html.Raw(BlogConfig.ContentSettings.CalloutSectionHtmlPitch)
        </section>
    }

    <div id="page-content" class="content">
        @if (null != ViewBag.ShowBloggerIntroInXS && ViewBag.ShowBloggerIntroInXS)
        {
            <section class="blogger-intro-mobile d-block d-sm-none">
                <div class="card-bkimg-container">
                    <img class="card-bkimg" alt="" src="@Url.Action("Avatar", "Assets")" />
                </div>
                <div class="blogger-intro-content">
                    <div class="row">
                        <div class="col-3">
                            <img src="@Url.Action("Avatar", "Assets")"
                                 alt="@BlogConfig.GeneralSettings.OwnerName"
                                 class="rounded-circle blogger-head-pic" />
                        </div>
                        <div class="col-9">
                            <h4 class="text-center">
                                @BlogConfig.GeneralSettings.ShortDescription
                            </h4>
                        </div>
                    </div>
                </div>
            </section>
        }
        @if (null != ViewBag.HideSideBar && ViewBag.HideSideBar)
        {
            @RenderBody()
        }
        else
        {
            <div class="container mt-4 mb-5">
                <div class="row">
                    <section class="col-lg-9 col-md-12">
                        @RenderBody()
                    </section>
                    <partial name="_Aside" />
                </div>
            </div>
        }
    </div>
    <div class="clearfix"></div>
    <partial name="_Footer" />

    @await RenderSectionAsync("scripts", false)
    @if (BlogConfig.GeneralSettings.AutoDarkLightTheme)
    {
        <script>
            'use strict';
            if (window.matchMedia && window.themeModeSwitcher && supportLightSwitch) {
                if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
                    themeModeSwitcher.useDarkMode();
                }
                else {
                    themeModeSwitcher.useLightMode();
                }
            }
        </script>
    }
</body>
</html>
